<template>
  <div class="title">
    <h1>红浪漫洗浴中心后台管理系统</h1>
    <el-tabs type="border-card" v-model="currentTab" stretch>
      <el-tab-pane name="account">
        <template #label>
          <span><i class="el-icon-user-solid"></i> 账号登录</span>
        </template>
        <login-account ref="accountRef" />
      </el-tab-pane>
      <el-tab-pane name="phone">
        <template #label>
          <span><i class="el-icon-mobile-phone"></i> 手机登录</span>
        </template>
        <login-phone />
      </el-tab-pane>
    </el-tabs>
    <div class="account-cortol">
      <el-checkbox v-model="isKeepPassword">记住密码</el-checkbox>
      <el-link type="primary">忘记密码</el-link>
    </div>
    <el-button type="primary" class="button" @click="handleLoginClick"
      >立即登录</el-button
    >
  </div>
</template>

<script lang="ts">
import { defineComponent, ref } from 'vue'
import { ElTabs, ElTabPane, ElCheckbox, ElLink } from 'element-plus'

import loginAccount from './loginAccount.vue'
import loginPhone from './loginPhone.vue'

export default defineComponent({
  components: {
    ElTabs,
    ElTabPane,
    ElCheckbox,
    ElLink,

    loginAccount,
    loginPhone
  },
  setup() {
    const isKeepPassword = ref(true)
    const currentTab = ref('account')
    const accountRef = ref<InstanceType<typeof loginAccount>>()

    const handleLoginClick = () => {
      if (currentTab.value === 'account') {
        accountRef.value?.loginActive(isKeepPassword.value)
      } else {
        console.log('phoneRef调用loginAction')
      }
    }
    return {
      isKeepPassword,
      handleLoginClick,
      accountRef,
      currentTab
    }
  }
})
</script>

<style lang="less" scoped>
.title {
  text-align: center;
}
.account-cortol {
  margin-top: 8px;
  display: flex;
  justify-content: space-between;
}
.button {
  width: 100%;
  margin: 10px;
}
</style>
